import 'package:PLDroidMediaStreaming/PLDroidMediaStreaming.dart';
import 'package:PLDroidMediaStreaming/controller/MediaStreamingManager.dart';
import 'package:flutter/widgets.dart';

class PLDroidMediaStreamingView extends StatefulWidget {
  PLDroidMediaStreamingView({Key key, this.manager }) : super(key: key);

  final MediaStreamingManager manager;

  @override
  _PLDroidMediaStreamingViewState createState() => _PLDroidMediaStreamingViewState();
}

class _PLDroidMediaStreamingViewState extends State<PLDroidMediaStreamingView> {

  Widget _nativeView;
  int _viewId;

  @override
  void initState() {
    super.initState();
    _nativeView = PLDroidMediaStreaming.createNativeView(
      (viewId) {
        _viewId = viewId;
      }, 
      manager: widget.manager
    );
  }

  @override
  void dispose() { 
    PLDroidMediaStreaming.removeLocalView(_viewId);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return _nativeView ?? Container();
  }
}